package xyz.bali16.module.article.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.base.Preconditions;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xyz.bali16.module.article.entity.Category;
import xyz.bali16.module.article.entity.Category;
import xyz.bali16.module.article.mapper.CategoryMapper;
import xyz.bali16.module.article.mapper.CategoryMapper;

import xyz.bali16.module.article.model.category.CategoryAddParam;
import xyz.bali16.module.article.model.category.CategoryPageParam;
import xyz.bali16.module.article.model.category.CategoryUpdateParam;
import xyz.bali16.module.article.service.CategoryService;

@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {


    @Override
    public IPage<Category> getPage(CategoryPageParam param) {
        IPage<?> page = new Page<>(param.getCurrent(), param.getSize());
        return this.baseMapper.getCategoryPage(page, param.getName(),param.getUrl());
    }

    @Override
    public void addCategory(CategoryAddParam param) throws Exception {
        Preconditions.checkNotNull(param, "CommentAddParam 参数不能为为空");
        Category category = new Category();
        BeanUtils.copyProperties(param, category);
        System.out.println(category);
        save(category);
    }

    @Override
    public void updateCategory(CategoryUpdateParam param) throws Exception {
        Preconditions.checkNotNull(param, "CommentAddParam 参数不能为为空");
        Category category = new Category();
        BeanUtils.copyProperties(param, category);
        updateById(category);
    }

    @Override
    public void delete(String categoryId) throws Exception {
        if (categoryId == null) {
            return;
        }
        removeById(categoryId);
    }

}

